import com.baidu.translate.demo.TransApi;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Main {

    // 在平台申请的APP_ID 详见 http://api.fanyi.baidu.com/api/trans/product/desktop?req=developer
    private static final String APP_ID = "20211006000965479";
    private static final String SECURITY_KEY = "3oPq1XsnnEgVxrPVYjkm";

    public static void main(String[] args) {
        TransApi api = new TransApi(APP_ID, SECURITY_KEY);
        //测试代码，每次开启后都会运行，如果出错会自动报错
        String query = "我叫张正刚哈哈哈哈哈哈";
        String out=api.getTransResult(query, "auto", "en");
        System.out.println(out);
        JSONObject jsonObject = JSONObject.fromObject(out);
        JSONArray arr = jsonObject.getJSONArray("trans_result");
        System.out.println(arr);
        JSONObject subObj = arr.getJSONObject(0);
        System.out.println("要翻译的字符:"+subObj.getString("src")+" 翻译结果:"+subObj.getString("dst"));
        
        
        //GUI编程
        MyFrame myframe=new MyFrame();
        myframe.init();
    }
}
